<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <title>生意帮</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../../css/common.css" />
    <link rel="stylesheet" type="text/css" href="../../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../../css/aui-pull-refresh.css" />
    <link rel="stylesheet" type="text/css" href="../../css/swiper.min.css">
    <link rel="stylesheet" type="text/css" href="../../css/aui-slide.css" />
    <style>
        html,
        body {
            background-color: transparent;
        }
        .boxB {
          position: relative;;
          width: 100%;
          height: 100vh;
        }
        .mask {
          position: absolute;
          width: 100%;
          height: 100%;
          background-color: rgba(0,0,0,0.3);
        }
        .box {
            background-color: #fff;
            position: absolute;
            left: 0;
            bottom: 0;
            width: 100%;
        }

        .aui-content {
        }

        .head_right .aui-pull-right {
            border: 1px solid #999;
            border-radius: 50%;
            height: 1rem;
            width: 1rem;
            text-align: center;
            line-height: 1rem;
        }

        .aui-iconfont {
            font-size: 0.6rem;
            vertical-align: top;
        }

        .head_right {
            position: relative;
        }


        .clearfix:after {
            content: '';
            display: block;
            clear: both;
        }
        #app .aui-list-header {
          background: #fff;
        }
        .aui-list-header i {
          font-style: normal;
          font-size: 1rem;
        }
        .Submit {
          background: url(../../image/header_bg.png) no-repeat center !important;
          font-size: 0.8rem;
          color: #fff;
          text-align: center;
          padding: 0.5rem 0
        }
    </style>
</head>

<body>
  <div id="app">
    <div class="boxB">
      <div class="mask" onclick="openF()"></div>
        <div class="box">
          <div class="aui-content">
                  <ul class="aui-list aui-media-list">
                      <li class="aui-list-header">
                          请选择支付方式   <i onclick="openF()">×</i>
                      </li>
                      <li class="aui-list-item aui-list-item-middle" @click="pay(2)">
                          <div class="aui-media-list-item-inner">
                              <div class="aui-list-item-media" style="width: 2rem;">
                                  <img src="../../image/my/m42.png" class="aui-list-img-sm">
                              </div>
                              <div class="aui-list-item-inner">
                                  <div class="aui-list-item-text">
                                      <div class="aui-list-item-title aui-font-size-14">支付宝支付</div>
                                  </div>
                              </div>
                          </div>
                      </li>
                      <li class="aui-list-item aui-list-item-middle" @click="pay(1)">
                          <div class="aui-media-list-item-inner">
                              <div class="aui-list-item-media" style="width: 2rem;">
                                  <img src="../../image/my/m41.png" class="aui-list-img-sm">
                              </div>
                              <div class="aui-list-item-inner">
                                  <div class="aui-list-item-text">
                                      <div class="aui-list-item-title aui-font-size-14">微信支付</div>
                                  </div>
                              </div>
                          </div>
                      </li>
                      <li class="aui-list-item aui-list-item-middle" @click="pay(3)">
                          <div class="aui-media-list-item-inner">
                              <div class="aui-list-item-media" style="width: 2rem;">
                                  <img src="../../image/my/m40.png" class="aui-list-img-sm">
                              </div>
                              <div class="aui-list-item-inner">
                                  <div class="aui-list-item-text">
                                      <div class="aui-list-item-title aui-font-size-14">银联支付</div>
                                  </div>
                              </div>
                          </div>
                      </li>
                      <li class="aui-list-item aui-list-item-middle" @click="pay(4)">
                          <div class="aui-media-list-item-inner">
                              <div class="aui-list-item-media" style="width: 2rem;">
                                  <img src="../../image/my/m43.png" class="aui-list-img-sm">
                              </div>
                              <div class="aui-list-item-inner">
                                  <div class="aui-list-item-text">
                                      <div class="aui-list-item-title aui-font-size-14">余额支付</div>
                                  </div>
                              </div>
                          </div>
                      </li>
                  </ul>
              </div>
            <!-- <div class="Submit">
                确认支付
            </div> -->
        </div>
    </div>
  </div>

</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/zepto.js"></script>
<script type="text/javascript" src="../../script/vue.min.js"></script>
<script type="text/javascript" src="../../script/utils.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script type="text/javascript" src="../../script/aui-tab.js"></script>
<script type="text/javascript" src="../../script/aui-scroll.js"></script>
<script type="text/javascript" src="../../script/aui-pull-refresh.js"></script>
<script type="text/javascript" src="../../script/swiper.min.js"></script>
<script type="text/javascript" src="../../script/aui-slide.js"></script>
<script type="text/javascript" src="../../script/aui-lazyload.js"></script>
<script type="text/javascript">
    function openF() {
      api.execScript({
          name: 'orderAll',
          script: 'window.location.reload()'
      })
      api.closeWin({
        name: "order",
        animation: {
            type:"none",
            duration: 0,
        }
      })
        api.closeFrame({
          animation: {
              type:"none",
              duration: 0,
          }
        });
    }

    apiready = function() {
      var app = new Vue({
        el: '#app',
        data: {
        },
        created: function() {
          var $_this = this;
          api.showProgress({
              title: '努力加载中...',
              text: '先喝杯茶...',
              modal: false
          });
          api.ajax({
            url: window.Url.Freegoods_getGoodsSku,
            method: 'post',
            data: {
              values: {
                goodsId: api.pageParam.id,
                token: $api.getStorage('token')
              }
            }
          }, function(ret, err) {
              if (ret) {

              } else {
                  api.alert({ msg: JSON.stringify(err) });
              }
          })
        },
        methods: {
          pay: function (type) {
            // alert(api.pageParam.order_id)
            if (type == 4) {
              api.addEventListener({
                  name: 'sendPW'
              }, function(ret, err) {
                api.ajax({
                    url: window.Url.Freepay_toPay,
                    method: 'post',
                    data: {
                        values: {
                            token: $api.getStorage('token'),
                            order_no: api.pageParam.order_no,
                            password: ret.value.password,
                            type: type,
                            pay_class: api.pageParam.under_type  //201808111711107f7260
                        }
                    }
                }, function(ret, err) {
                  console.log(JSON.stringify(ret))
                  api.toast({ msg: ret.info,duration: 2000,location:'middle' });
                  if (ret.re == 1) {
                    // api.openWin({
                    //     name: 'order_ok',
                    //     url: './order_ok_header.html'
                    // });
                    if(api.pageParam.order_id.length==1){
                      api.openWin({
                          name: 'order_evaluate',
                          url: '../five_frame/headerone.html',
                          pageParam: {
                              msg:'订单详情',
                              url:'../five_frame/order_evaluate1.html',
                              id: api.pageParam.order_id
                          }
                      })
                    }
                    else{
                      api.openWin({
                          name: 'order_evaluate',
                          url: '../five_frame/headerone.html',
                          pageParam: {
                              msg:'订单详情',
                              url:'../five_frame/order_evaluate2.html',
                              id: api.pageParam.order_id
                          }
                      })
                    }

                    openF()
                  }
                })
              });
            api.ajax({
                url: window.Url.Freeucenter_takepassword,
                method: 'post',
                data: {
                    values: {
                        token: $api.getStorage('token')
                    }
                }
            },function(ret, err){
                if (ret.re == 1) {
                  api.openFrame({
                      name: 'pay_password',
                      url: '../five_frame/pay_password.html',
                      pageParam: {
                        type: 'getPW'
                      }
                  });
                } else {

                    api.openWin({
                        name: 'type',
                        url: '../five_frame/payPassword.html',
                        pageParam: {
                            list:2
                        }
                    });
                }
            });



          } else if (type == 1 || type == 2 || type == 3) {
              api.ajax({
                  url: window.Url.Freepay_toPay,
                  method: 'post',
                  data: {
                      values: {
                          token: $api.getStorage('token'),
                          order_no: api.pageParam.order_no,
                          password: null,
                          type: type,
                          pay_class: api.pageParam.under_type  //201808111711107f7260
                      }
                  }
              }, function(ret, err) {
                  if (ret) {
                    if (type == 2) {
                      var aliPay = api.require('aliPay');
                      aliPay.payOrder({
                          orderInfo: ret.data.pay_info
                      }, function(ret, err) {
                          switch (ret.code) {
                            case '9000':
                              // api.toast({ msg: '支付成功',duration: 2000,location:'middle' });
                              api.openWin({
                                  name: 'order_evaluate',
                                  url: '../five_frame/headerone.html',
                                  pageParam: {
                                      msg:'订单详情',
                                      url:'../five_frame/order_evaluate.html',
                                      id: api.pageParam.order_id
                                  }
                              })
                              openF()
                              break;
                            case '4000':
                              api.toast({ msg: '系统异常',duration: 2000,location:'middle' });
                              break;
                            case '4001':
                              api.toast({ msg: '数据格式不正确',duration: 2000,location:'middle' });
                              break;
                            case '4003':
                              api.toast({ msg: '该用户绑定的支付宝账户被冻结或不允许支付',duration: 2000,location:'middle' });
                              break;
                            case '4004':
                              api.toast({ msg: '该用户已解除绑定',duration: 2000,location:'middle' });
                              break;
                            case '4005':
                              api.toast({ msg: '绑定失败或没有绑定',duration: 2000,location:'middle' });
                              break;
                            case '4006':
                              api.toast({ msg: '订单支付失败',duration: 2000,location:'middle' });
                              break;
                            case '4010':
                              api.toast({ msg: '重新绑定账户',duration: 2000,location:'middle' });
                              break;
                            case '6000':
                              api.toast({ msg: '支付服务正在进行升级操作',duration: 2000,location:'middle' });
                              break;
                            case '6001':
                              api.toast({ msg: '用户中途取消支付操作',duration: 2000,location:'middle' });
                              break;
                            default:
                              api.toast({ msg: ret.code,duration: 2000,location:'middle' });
                          }
                      });
                    } else if (type == 1) {
                      var weiXin = api.require('weiXin');
                      weiXin.payOrder({
                          orderId: ret.data.pay_info.prepayid,
                          partnerId: ret.data.pay_info.partnerid,
                          nonceStr: ret.data.pay_info.noncestr,
                          timeStamp: ret.data.pay_info.timestamp,
                          package: ret.data.pay_info.package,
                          sign: ret.data.pay_info.sign
                      }, function(re, er) {
                          if (re.status) {
                            api.openWin({
                                name: 'order_evaluate',
                                url: '../five_frame/headerone.html',
                                pageParam: {
                                    msg:'订单详情',
                                    url:'../five_frame/order_evaluate.html',
                                    id: api.pageParam.order_id
                                }
                            })
                            openF()
                          }
                      })

                    } else if (type == 3) {

                      // 临时插入
                      api.toast({ msg: '暂未开通',duration: 2000,location:'middle' });
                      return
                      // 临时插入

                      var unPay = api.require('unionPay');
                      console.log(ret.data.pay_info);
                      unPay.pay({
                          tn: ret.data.pay_info,
                          devMode: false
                      }, function(ret, err){
                      })
                    } else {
                      api.toast({ msg: '暂未开通',duration: 2000,location:'middle' });
                      return
                    }

                  } else {
                      api.alert({
                          msg: JSON.stringify(err)
                      });
                  }
              })
            } else {
              api.toast({ msg: '暂未开通',duration: 2000,location:'middle' });
              return
            }


          }

        },
        mounted: function () {
          api.hideProgress();
        }
      })
    }
</script>

</html>
